package com.wilson.integration.lease.admin.controller.apartment;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wilson.integration.lease.admin.service.ApartmentInfoService;
import com.wilson.integration.lease.common.entity.ApartmentInfo;
import com.wilson.integration.lease.common.entity.vo.apartment.ApartmentDetailVO;
import com.wilson.integration.lease.common.entity.vo.apartment.ApartmentItemVO;
import com.wilson.integration.lease.common.entity.vo.apartment.ApartmentQueryVO;
import com.wilson.integration.lease.common.entity.vo.apartment.ApartmentSubmitVO;
import com.wilson.integration.lease.common.enums.ReleaseStatus;
import com.wilson.integration.lease.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "公寓信息管理")
@RestController
@RequestMapping("/admin/apartment")
public class ApartmentController {

    @Resource
    private ApartmentInfoService apartmentInfoService;

    @Operation(summary = "保存或更新公寓信息")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody ApartmentSubmitVO apartmentSubmitVO) {
        apartmentInfoService.saveOrUpdateApartment(apartmentSubmitVO);
        return Result.ok();
    }

    @Operation(summary = "根据条件分页查询公寓列表")
    @GetMapping("pageItem")
    public Result<IPage<ApartmentItemVO>> pageItem(@RequestParam long current, @RequestParam long size, ApartmentQueryVO queryVO) {
        IPage<ApartmentItemVO> page = new Page<>(current, size);
        return Result.ok(apartmentInfoService.pageApartmentItemByQuery(page, queryVO));
    }

    @Operation(summary = "根据ID获取公寓详细信息")
    @GetMapping("getDetailById")
    public Result<ApartmentDetailVO> getDetailById(@RequestParam Long id) {
        return Result.ok(apartmentInfoService.getApartmentDetailById(id));
    }

    @Operation(summary = "根据id删除公寓信息")
    @DeleteMapping("removeById")
    public Result removeById(@RequestParam Long id) {
        apartmentInfoService.removeApartmentById(id);
        return Result.ok();
    }

    @Operation(summary = "根据id修改公寓发布状态")
    @PostMapping("updateReleaseStatusById")
    public Result updateReleaseStatusById(@RequestParam Long id, @RequestParam ReleaseStatus status) {
        apartmentInfoService.update(
                new LambdaUpdateWrapper<ApartmentInfo>()
                        .eq(ApartmentInfo::getId, id)
                        .set(ApartmentInfo::getIsRelease, status));
        return Result.ok();
    }

    @Operation(summary = "根据区县id查询公寓信息列表")
    @GetMapping("listInfoByDistrictId")
    public Result<List<ApartmentInfo>> listInfoByDistrictId(@RequestParam Long id) {
        List<ApartmentInfo> apartmentInfoList = apartmentInfoService.list(
                new LambdaQueryWrapper<ApartmentInfo>()
                        .eq(ApartmentInfo::getDistrictId, id));
        return Result.ok(apartmentInfoList);
    }
}














